/*
* Copyright 2025 NXP
* NXP Proprietary. This software is owned or controlled by NXP and may only be used strictly in
* accordance with the applicable license terms. By expressly accepting such terms or by downloading, installing,
* activating and/or otherwise using the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms.  If you do not agree to be bound by the applicable license
* terms, then you may not retain, install, activate or otherwise use the software.
*/

#include "events_init.h"
#include <stdio.h>
#include "lvgl.h"

#if LV_USE_GUIDER_SIMULATOR && LV_USE_FREEMASTER
#include "freemaster_client.h"
#endif


static void screen_home_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_GESTURE:
    {
        lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
        switch(dir) {
        case LV_DIR_BOTTOM:
        {
            lv_indev_wait_release(lv_indev_get_act());
            ui_load_scr_animation(&guider_ui, &guider_ui.screen_information, guider_ui.screen_information_del, &guider_ui.screen_home_del, setup_scr_screen_information, LV_SCR_LOAD_ANIM_MOVE_BOTTOM, 200, 200, false, false);
            break;
        }
        case LV_DIR_RIGHT:
        {
            lv_indev_wait_release(lv_indev_get_act());
            ui_load_scr_animation(&guider_ui, &guider_ui.screen_ctrl, guider_ui.screen_ctrl_del, &guider_ui.screen_home_del, setup_scr_screen_ctrl, LV_SCR_LOAD_ANIM_MOVE_RIGHT, 200, 200, false, false);
            break;
        }
        default:
            break;
        }
        break;
    }
    default:
        break;
    }
}

void events_init_screen_home (lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_home, screen_home_event_handler, LV_EVENT_ALL, ui);
}

static void screen_information_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_GESTURE:
    {
        lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
        switch(dir) {
        case LV_DIR_TOP:
        {
            lv_indev_wait_release(lv_indev_get_act());
            ui_load_scr_animation(&guider_ui, &guider_ui.screen_home, guider_ui.screen_home_del, &guider_ui.screen_information_del, setup_scr_screen_home, LV_SCR_LOAD_ANIM_MOVE_TOP, 200, 200, false, false);
            break;
        }
        default:
            break;
        }
        break;
    }
    default:
        break;
    }
}

void events_init_screen_information (lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_information, screen_information_event_handler, LV_EVENT_ALL, ui);
}

static void screen_ctrl_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_GESTURE:
    {
        lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
        switch(dir) {
        case LV_DIR_RIGHT:
        {
            lv_indev_wait_release(lv_indev_get_act());
            ui_load_scr_animation(&guider_ui, &guider_ui.screen_home, guider_ui.screen_home_del, &guider_ui.screen_ctrl_del, setup_scr_screen_home, LV_SCR_LOAD_ANIM_MOVE_RIGHT, 200, 200, false, false);
            break;
        }
        default:
            break;
        }
        break;
    }
    default:
        break;
    }
}

static void screen_ctrl_btn_flashlight_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        ui_load_scr_animation(&guider_ui, &guider_ui.screen_flashlight, guider_ui.screen_flashlight_del, &guider_ui.screen_ctrl_del, setup_scr_screen_flashlight, LV_SCR_LOAD_ANIM_OVER_TOP, 200, 200, false, false);
        break;
    }
    default:
        break;
    }
}

static void screen_ctrl_btn_set_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        ui_load_scr_animation(&guider_ui, &guider_ui.screen_set, guider_ui.screen_set_del, &guider_ui.screen_ctrl_del, setup_scr_screen_set, LV_SCR_LOAD_ANIM_OVER_TOP, 200, 200, false, false);
        break;
    }
    default:
        break;
    }
}

static void screen_ctrl_btn_alarm_clock_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        ui_load_scr_animation(&guider_ui, &guider_ui.screen_alarm_clock, guider_ui.screen_alarm_clock_del, &guider_ui.screen_ctrl_del, setup_scr_screen_alarm_clock, LV_SCR_LOAD_ANIM_MOVE_TOP, 200, 200, false, false);
        break;
    }
    default:
        break;
    }
}

static void screen_ctrl_btn_led_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        ui_load_scr_animation(&guider_ui, &guider_ui.screen_LED, guider_ui.screen_LED_del, &guider_ui.screen_ctrl_del, setup_scr_screen_LED, LV_SCR_LOAD_ANIM_MOVE_TOP, 200, 200, false, false);
        break;
    }
    default:
        break;
    }
}

void events_init_screen_ctrl (lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_ctrl, screen_ctrl_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_ctrl_btn_flashlight, screen_ctrl_btn_flashlight_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_ctrl_btn_set, screen_ctrl_btn_set_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_ctrl_btn_alarm_clock, screen_ctrl_btn_alarm_clock_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_ctrl_btn_led, screen_ctrl_btn_led_event_handler, LV_EVENT_ALL, ui);
}

static void screen_flashlight_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_GESTURE:
    {
        lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
        switch(dir) {
        case LV_DIR_BOTTOM:
        {
            lv_indev_wait_release(lv_indev_get_act());
            ui_load_scr_animation(&guider_ui, &guider_ui.screen_ctrl, guider_ui.screen_ctrl_del, &guider_ui.screen_flashlight_del, setup_scr_screen_ctrl, LV_SCR_LOAD_ANIM_MOVE_BOTTOM, 200, 200, false, false);
            break;
        }
        default:
            break;
        }
        break;
    }
    default:
        break;
    }
}

void events_init_screen_flashlight (lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_flashlight, screen_flashlight_event_handler, LV_EVENT_ALL, ui);
}

static void screen_LED_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_GESTURE:
    {
        lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
        switch(dir) {
        case LV_DIR_BOTTOM:
        {
            lv_indev_wait_release(lv_indev_get_act());
            ui_load_scr_animation(&guider_ui, &guider_ui.screen_ctrl, guider_ui.screen_ctrl_del, &guider_ui.screen_LED_del, setup_scr_screen_ctrl, LV_SCR_LOAD_ANIM_MOVE_BOTTOM, 200, 200, false, false);
            break;
        }
        default:
            break;
        }
        break;
    }
    default:
        break;
    }
}

static void screen_LED_btn_open_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        lv_led_set_brightness(guider_ui.screen_LED_led_1, 255);
        break;
    }
    default:
        break;
    }
}

static void screen_LED_btn_close_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        lv_led_set_brightness(guider_ui.screen_LED_led_1, 0);
        break;
    }
    default:
        break;
    }
}

void events_init_screen_LED (lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_LED, screen_LED_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_LED_btn_open, screen_LED_btn_open_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_LED_btn_close, screen_LED_btn_close_event_handler, LV_EVENT_ALL, ui);
}

static void screen_alarm_clock_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_GESTURE:
    {
        lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
        switch(dir) {
        case LV_DIR_BOTTOM:
        {
            lv_indev_wait_release(lv_indev_get_act());
            ui_load_scr_animation(&guider_ui, &guider_ui.screen_ctrl, guider_ui.screen_ctrl_del, &guider_ui.screen_alarm_clock_del, setup_scr_screen_ctrl, LV_SCR_LOAD_ANIM_MOVE_BOTTOM, 200, 200, false, false);
            break;
        }
        default:
            break;
        }
        break;
    }
    default:
        break;
    }
}

static void screen_alarm_clock_cont_2_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        ui_load_scr_animation(&guider_ui, &guider_ui.screen_alarm_clock_set, guider_ui.screen_alarm_clock_set_del, &guider_ui.screen_alarm_clock_del, setup_scr_screen_alarm_clock_set, LV_SCR_LOAD_ANIM_MOVE_TOP, 200, 200, false, false);
        break;
    }
    default:
        break;
    }
}

void events_init_screen_alarm_clock (lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_alarm_clock, screen_alarm_clock_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_alarm_clock_cont_2, screen_alarm_clock_cont_2_event_handler, LV_EVENT_ALL, ui);
}

static void screen_alarm_clock_set_btn_1_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        ui_load_scr_animation(&guider_ui, &guider_ui.screen_alarm_clock, guider_ui.screen_alarm_clock_del, &guider_ui.screen_alarm_clock_set_del, setup_scr_screen_alarm_clock, LV_SCR_LOAD_ANIM_MOVE_BOTTOM, 200, 200, false, false);
        break;
    }
    default:
        break;
    }
}

void events_init_screen_alarm_clock_set (lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_alarm_clock_set_btn_1, screen_alarm_clock_set_btn_1_event_handler, LV_EVENT_ALL, ui);
}

static void screen_set_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_GESTURE:
    {
        lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
        switch(dir) {
        case LV_DIR_BOTTOM:
        {
            lv_indev_wait_release(lv_indev_get_act());
            ui_load_scr_animation(&guider_ui, &guider_ui.screen_ctrl, guider_ui.screen_ctrl_del, &guider_ui.screen_set_del, setup_scr_screen_ctrl, LV_SCR_LOAD_ANIM_MOVE_BOTTOM, 200, 200, false, false);
            break;
        }
        default:
            break;
        }
        break;
    }
    default:
        break;
    }
}

void events_init_screen_set (lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_set, screen_set_event_handler, LV_EVENT_ALL, ui);
}

static void screen_alarm_clock_remind_btn_1_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        ui_load_scr_animation(&guider_ui, &guider_ui.screen_home, guider_ui.screen_home_del, &guider_ui.screen_alarm_clock_remind_del, setup_scr_screen_home, LV_SCR_LOAD_ANIM_NONE, 200, 200, true, true);
        break;
    }
    default:
        break;
    }
}

static void screen_alarm_clock_remind_btn_2_event_handler (lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    switch (code) {
    case LV_EVENT_CLICKED:
    {
        ui_load_scr_animation(&guider_ui, &guider_ui.screen_home, guider_ui.screen_home_del, &guider_ui.screen_alarm_clock_remind_del, setup_scr_screen_home, LV_SCR_LOAD_ANIM_NONE, 200, 200, true, true);
        break;
    }
    default:
        break;
    }
}

void events_init_screen_alarm_clock_remind (lv_ui *ui)
{
    lv_obj_add_event_cb(ui->screen_alarm_clock_remind_btn_1, screen_alarm_clock_remind_btn_1_event_handler, LV_EVENT_ALL, ui);
    lv_obj_add_event_cb(ui->screen_alarm_clock_remind_btn_2, screen_alarm_clock_remind_btn_2_event_handler, LV_EVENT_ALL, ui);
}


void events_init(lv_ui *ui)
{

}
